<?php

/**
 * 区域划分类
 * Class Area
 * 按照坐标系划分每个客户位置
 */
namespace Units;
use function Clue\StreamFilter\fun;
use function GuzzleHttp\Promise\all;

class Area
{
       private $_first_quadrant=[];    //第一象限
       private $_second_quadrant = [];  //第二象限
       private $_third_quadrant = [];    //第三象限
       private $_fouth_quadrant =[];     //第四象限
       private $car_limit_stops = 17;       //每个区域每个车辆路线不超过坐标个数
       private $car_limit_weight = 6800;
       private $data=[];
       private $center=[];
       public function __construct(array $center ,  array $data , $car_limit_stops = null , $car_limit_weight = null)
       {
             $this->data = $data;
             $this->center = $center;

       }

    /**
     * 划分区域位置
     * @param array $data
     * @return array 每个区域的位置
     */
       public function regionalPoint( ) {
                 foreach ( $this->data as $key=> $val ) {
                      if( $val['lat'] == 0 || $val['lng'] == 0 ) {
                          break;
                      }

                       if( $val['lat'] > $this->center['lat'] && $val['lng'] > $this->center['lng'] ) {
                           $this->_first_quadrant[] = $val;
                       }
                      if( $val['lat'] > $this->center['lat'] && $val['lng'] < $this->center['lng'] ) {
                         $this->_second_quadrant[] = $val;
                      }
                      if( $val['lat'] < $this->center['lat'] && $val['lng'] < $this->center['lng'] ) {
                         $this->_third_quadrant[] = $val;
                     }
                      if( $val['lat'] < $this->center['lat'] && $val['lng'] > $this->center['lng'] ) {
                         $this->_fouth_quadrant[] = $val;
                      }
                 }
                 return [
                     $this->_first_quadrant,
                     $this->_second_quadrant,
                     $this->_third_quadrant,
                     $this->_fouth_quadrant
                 ];
       }
}